package com.atguigu.rwlock.rwlock;

import java.util.concurrent.locks.ReentrantReadWriteLock;
public class ReadWriteLockDemo2
{
    private ReentrantReadWriteLock rwLock = new ReentrantReadWriteLock();
    public void test(){
        rwLock.writeLock().lock();
        System.out.println("获取到写锁=开写");

        rwLock.readLock().lock();
        System.out.println("获取到读锁=开读");
        rwLock.writeLock().unlock();
        //读数据
        //可以插入其他的读线程（因为读读可并发），从而提高应用程序的执行效率
        System.out.println("释放写锁==");
        rwLock.readLock().unlock();
        System.out.println("释放读锁==");
    }
}
